//
//  ByCoreToolAlert.m
//  beibei_ios
//
//  Created by hebidu on 16/4/16.
//  Copyright © 2016年 hebidu. All rights reserved.
//

#import "ByCoreToolAlert.h"

@interface ByCoreToolAlert() 

@end

@implementation ByCoreToolAlert

#pragma mark - 使用sv实现的弹框提醒
/** 设置默认的HUD弹框 */
+ (void)defaultCustomHUD {
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom]; // 自定义弹框
//    [SVProgressHUD setBackgroundColor:[UIColor colorWithRed:1 green:140/255.0 blue:190/255.0 alpha:0.8]]; // 弹窗背景框颜色
    [SVProgressHUD setBackgroundColor:JM_THEME_COLOR_WITH_APPHA(0.8)]; // 弹窗背景框颜色


    [SVProgressHUD setForegroundColor:[UIColor whiteColor]]; // 字和进度条的颜色
//    [SVProgressHUD setBackgroundLayerColor:MW_THEME_COLOR];
    [SVProgressHUD setRingThickness:4]; // 圆环厚度
    [SVProgressHUD setRingRadius:15]; // 圆环半径
    [SVProgressHUD setRingNoTextRadius:20]; // 没有文字时圆环半径
    [SVProgressHUD setMinimumDismissTimeInterval:2];
    
    // 图片
    [SVProgressHUD setErrorImage:[UIImage imageNamed:@"失败"]];
    [SVProgressHUD setSuccessImage:[UIImage imageNamed:@"成功"]];
    
//    UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; // 字体
//    font = [font fontWithSize:14];
    UIFont *font = [UIFont boldSystemFontOfSize:14];
    [SVProgressHUD setFont:font];
}


/** 添加遮罩视图 */
+ (void)alertAddMask:(SVProgressHUDMaskType)maskType {
    
    [SVProgressHUD setDefaultMaskType:maskType];
}


#pragma mark - info
/** 信息弹框 只有文字 */
+ (void)alertInfo:(NSString *)info {
    
    [self defaultCustomHUD];
    [SVProgressHUD showImage:nil status:info];
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];

}
/** 信息弹框（自定义图片，image为nil则用默认图片）*/
+ (void)alertInfo:(NSString *)info image:(UIImage *)image {
    
    [self defaultCustomHUD];
    if (image) {
        [SVProgressHUD showImage:image status:info];
    } else {
        [SVProgressHUD showInfoWithStatus:info];
    }
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];

}

#pragma mark - 成功
/** 成功弹框（有默认图片）*/
+ (void)alertSuccess:(NSString *)info {
    
    [self defaultCustomHUD];
    [SVProgressHUD showSuccessWithStatus:info];
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];

}
/** 成功弹框（有默认图片），自定义消失时间 */
+ (void)alertSuccess:(NSString *)info duration:(NSTimeInterval)duration {
    [self defaultCustomHUD];
    [SVProgressHUD setMinimumDismissTimeInterval:duration];
    [SVProgressHUD showSuccessWithStatus:info];
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];

}
/** 成功弹框（自定义图片，image为nil则用默认图片）*/
+ (void)alertSuccess:(NSString *)info image:(UIImage *)image {
    
    [self defaultCustomHUD];
    [SVProgressHUD setSuccessImage:image];
    [SVProgressHUD showSuccessWithStatus:info];
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];

}
/** 成功弹框（自定义图片，image为nil则用默认图片），自定义消失时间 */
+ (void)alertSuccess:(NSString *)info image:(UIImage *)image duration:(NSTimeInterval)duration {
    [self defaultCustomHUD];
    [SVProgressHUD setSuccessImage:image];
    [SVProgressHUD setMinimumDismissTimeInterval:duration];
    [SVProgressHUD showSuccessWithStatus:info];
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];

}

#pragma mark - 失败
/** 失败弹框（有默认图片）*/
+ (void)alertError:(NSString *)info {
    
    [self defaultCustomHUD];
    [SVProgressHUD showErrorWithStatus:info];
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];

}
/** 失败弹框（有默认图片），自定义消失时间 */
+ (void)alertError:(NSString *)info duration:(NSTimeInterval)duration {
    [self defaultCustomHUD];
    [SVProgressHUD setMinimumDismissTimeInterval:duration];
    [SVProgressHUD showErrorWithStatus:info];
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];

}
/** 失败弹框（自定义图片，image为nil则用默认图片）*/
+ (void)alertError:(NSString *)info image:(UIImage *)image {
    
    [self defaultCustomHUD];
    [SVProgressHUD setErrorImage:image];
    [SVProgressHUD showErrorWithStatus:info];
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];

}
/** 失败弹框（自定义图片，image为nil则用默认图片），自定义消失时间 */
+ (void)alertError:(NSString *)info image:(UIImage *)image duration:(NSTimeInterval)duration {
    [self defaultCustomHUD];
    [SVProgressHUD setErrorImage:image];
    [SVProgressHUD setMinimumDismissTimeInterval:duration];
    [SVProgressHUD showErrorWithStatus:info];
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];

}
#pragma mark - 加载
/** 加载中 */
+ (void)alertLoading:(NSString *)info {
    
    [self defaultCustomHUD];
    [SVProgressHUD showWithStatus:info];
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];

}

#pragma mark - 进度
/** 进度条 */
+ (void)alertProgress:(CGFloat)progress info:(NSString *)info {
    
    [self defaultCustomHUD];
    [SVProgressHUD showProgress:progress status:info];
    
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeNone];
}

#pragma mark -
/** 弹框消失 */
+ (void)alertDismiss {
    [SVProgressHUD dismiss];
}
@end
